<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=pageContext.getServletContext().getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>门诊收费</title>
	<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="<%=path %>/eazyui/demo/demo.css">
	<script type="text/javascript" src="<%=path %>/eazyui/jquery.min.js"></script>
	<script type="text/javascript" src="<%=path %>/eazyui/jquery.easyui.min.js"></script>
	<script>

	function findPatientInfo(){
		var patient_name = document.getElementById("name").value;
		var patient_idcard = document.getElementById("number").value;
		$.post("<%=path %>/charge/getPatient",{patient_name:patient_name,patient_idcard:patient_idcard},function(data,textStatus){
				if(textStatus=="success"){
				console.log(data);
				$.each(data,function(index,result){
					result.patient_sex =result.patient_sex==0?"女":"男";
				})
				if(eval(data).length>0){
					$('#patientInfo').show();
					$('#patientDg').datagrid('resize');
					$('#patientDg').datagrid('loadData',{'total':eval(data).length,rows:data});
				}else{
					$('#patientInfo').hide();
				}
			}
		})
		$.post("<%=path %>/charge/getCmPrescription",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				if(eval(data).length>0){
					//$('#cmInfoDiv').css("display","block");
					$('#cmInfoDiv').show();
					$('#cmInfo').datagrid('resize');
					$('#cmInfo').datagrid('loadData',{'total':eval(data).length,rows:data});
				}else{
					//$('#cmInfoDiv').css("display","none");
					$('#cmInfoDiv').hide();
					}
				}
			})
		$.post("<%=path %>/charge/getWmPrescription",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				if(eval(data).length>0){
					//$('#wmInfoDiv').css("display","block");
					$('#wmInfoDiv').show();
					$('#wmInfo').datagrid('resize');
					$('#wmInfo').datagrid('loadData',{'total':eval(data).length,rows:data});
				}else{
					//$('#wmInfoDiv').css("display","none");
					$('#wmInfoDiv').hide();
					}
				}
			})
		$.post("<%=path %>/charge/getCkPrescription",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				if(eval(data).length>0){
					//$('#ckInfoDiv').css("display","block");
					$('#ckInfoDiv').show();
					$('#ckInfo').datagrid('resize');
					$('#ckInfo').datagrid('loadData',{'total':eval(data).length,rows:data});
				}else{
					//$('#ckInfoDiv').css("display","none");
					$('#ckInfoDiv').hide();
					}
				}
			})
		$.post("<%=path %>/charge/wmSum",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				$('#wmSum').html(data);
				}
			})
		$.post("<%=path %>/charge/cmSum",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				$('#cmSum').html(data);
				}
			})
		$.post("<%=path %>/charge/ckSum",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				$('#ckSum').html(data);
				}
			})
		$.post("<%=path %>/charge/allSum",{},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				$('#allSum').html(data);
				$('#allSum2').html(data);
				}
			})
			
	}
	
	function insertFee(){
		var shishou = document.getElementById("getCharge").value;
		var yingshou = $('#allSum').html();
		var zhaoling = shishou-yingshou;
		var ls_data = new Date();
		$.post("<%=path %>/charge/insertFee",{ls_data:ls_data},function(data,textStatus){
			if(textStatus=="success"){
				console.log(data);
				alert("收费成功");
				alert("找零："+zhaoling+"元");
				$('#addFee').window('close')
				findPatientInfo();
				}
			})
	}
	
	function close(){
		$('#addFee').window('close')
	}
	</script>
</head>
<body>
	<div>
		<form id="findFeeList"   method="post" style="margin:0px;display:inline;">
			<div>
			<input class="form-control" type="hidden" id="guahao_id"  name='guahao_id'>  
				<label for="supplementid">身份证号码</label>
				<input class="form-control"  type='text' id="number"  name='number'>  
				<label for="supplementid">姓名</label>
				<input class="form-control"  type='text' id="name"  name='name'>  
				<a href="#" class="easyui-linkbutton"  style="width:10%;height:25px;margin:25px auto;" onclick="findPatientInfo()" >查询</a>
			</div>
		</form>
		<br>
		<form id="allInfo" method="post">
			<div id="patientInfo" style="margin:0;display:none;">
			<table id="patientDg" class="easyui-datagrid" style="width:100%" >
    		<thead>
				<tr>
					<th field="patient_name" width="25%">姓名</th>
					<th field='patient_age'" width="25%">年龄</th>
					<th field='patient_sex'" width="25%">性别</th>
					<th field='patient_idcard'" width="25%">身份证号</th>					
				</tr>				
    		</thead>	
    		<tbody>
    			
    		</tbody>
    		</table>
   			</div>
			<br>	   
			<!-- 药品信息 --> 
			<div id="wmInfoDiv" style="display:none;">
			<table id="wmInfo" class="easyui-datagrid">
				<thead>
				<tr>
					<th field="wm_name" width="25%">西药名称</th>
					<th field="wm_id" width="25%">药品代码</th>			
					<th field="wm_price" width="15%">单价</th>
					<th field="wm_num" width="10%">数量</th>
					<th field="wm_amount" width="25%">合计金额</th>		
				</tr>				
    			</thead>	
				<tbody>
    				
				</tbody>	
			</table>
			药费合计：<span id="wmSum"></span>元
			</div>
			<br><br><br>
			<div id="cmInfoDiv" style="display:none;">
			<table id="cmInfo" class="easyui-datagrid">
				<thead>
				<tr>
					<th field="cm_name" width="25%">中药名称</th>
					<th field="cm_id" width="25%">药品代码</th>				
					<th field="cm_price" width="15%">单价</th>
					<th field="cm_num" width="10%">数量</th>
					<th field="cm_amount" width="25%">合计金额</th>
				</tr>				
    			</thead>	
				<tbody>
					  
				</tbody>	
			</table>
			药费合计：<span id="cmSum"></span>元
			</div>
			<br><br><br>
			<!-- 项目信息 --> 
			<div id="ckInfoDiv" style="display:none;">
			<table id="ckInfo" class="easyui-datagrid">
				<thead>
				<tr>
					<th field="ck_name" width="25%">项目名称</th>
					<th field="ck_id" width="25%">项目编号</th>			
					<th field="ck_price" width="15%">单价</th>
					<th field="ck_num" width="10%">数量</th>
					<th field="ck_amount" width="25%">合计金额</th>
				</tr>				
    			</thead>	
				<tbody>
    				 
				</tbody>	
            </table>
			项目合计：<span id="ckSum"></span>元
			</div>
            <br><br><br>
            <div id="getFee">
				<label for="regname" >应缴纳费用：<span id="allSum"></span>元</label><br>
				<a href="#"  class="easyui-linkbutton"  style="width:10%;height:32px;margin:5px auto;" onclick="$('#addFee').window('open')" >收费</a>
			</div> 
		</form>
	</div>
	<div id="addFee" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:600px;height:300px;padding:10px;">
				<div style="margin:0 auto;width:60%">
					<h2>应缴纳费用：<span id="allSum2"></span>元<h2>
				</div>
				<div style="margin:0 auto;width:60%">
				<div>实收金额：</div>
					<input class="easyui-textbox" id="getCharge" style="width:100%;height:32px;" onkeyup="shishou()"/>
				</div>
				<div style="margin:0 auto;width:60%">
					<a href="#" class="easyui-linkbutton"  style="width:40%;height:32px;margin:25px auto;" onclick="insertFee()" >确定</a>
					<a href="#" class="easyui-linkbutton"  style="width:40%;height:32px;margin:25px auto;" onclick="close()" >取消</a>
				</div>
			</div>
</body>
</html>